package com.bz.xtcx.manager.mapper;

import com.bz.xtcx.manager.entity.BusUser;
import com.bz.xtcx.manager.entity.CmsMeeting;
import com.bz.xtcx.manager.mapper.provider.CmsMeetingProvider;
import com.bz.xtcx.manager.persist.conditions.MeetingCondition;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.StatementType;

import java.util.List;

public interface CmsMeetingMapper {

    @InsertProvider(type = CmsMeetingProvider.class, method = "insertSelectiveProvider")
    @SelectKey(before = true, keyProperty = "id", resultType = String.class, statementType = StatementType.STATEMENT, statement="select uuid()")
    int insertSelective(CmsMeeting record);

    @UpdateProvider(type = CmsMeetingProvider.class, method = "updateByPrimaryKeySelectiveProvider")
    int updateByPrimaryKeySelective(CmsMeeting record);

    @SelectProvider(type = CmsMeetingProvider.class, method = "countByConditionProvider")
    int countByCondition(MeetingCondition mc);

    @SelectProvider(type = CmsMeetingProvider.class, method = "selectByConditionProvider")
    @Results(
            id = "cmsMeetingRow",
            value = {
                    @Result(property = "id", column = "id"),
                    @Result(property = "code", column = "code"),
                    @Result(property = "typeId", column = "type_id"),
                    @Result(property = "fromer", column = "fromer"),
                    @Result(property = "fromerContactsName", column = "fromer_contacts_name"),
                    @Result(property = "fromerContactsPhone", column = "fromer_contacts_phone"),
                    @Result(property = "fromerContactsMail", column = "fromer_contacts_mail"),
                    @Result(property = "fromerContactsAddr", column = "fromer_contacts_addr"),
                    @Result(property = "targeter", column = "targeter"),
                    @Result(property = "applicationContentId", column = "application_content_id"),
                    @Result(property = "applicationNote", column = "application_note"),
                    @Result(property = "submitTime", column = "submit_time"),
                    @Result(property = "checkStatus", column = "check_status"),
                    @Result(property = "reqMobileStatus", column = "req_mobile_status"),
                    @Result(property = "reqMailStatus", column = "req_mail_status"),
                    @Result(property = "respMobileStatus", column = "resp_mobile_status"),
                    @Result(property = "respMailStatus", column = "resp_mail_status"),
                    @Result(property = "reqMobileCnt", column = "req_mobile_cnt"),
                    @Result(property = "reqMailCnt", column = "req_mail_cnt"),
                    @Result(property = "respMobileCnt", column = "resp_mobile_cnt"),
                    @Result(property = "respMailCnt", column = "resp_mail_cnt"),
                    @Result(property = "checkContent", column = "check_content"),
                    @Result(property = "checkTime", column = "check_time"),
                    @Result(property = "refuseCount", column = "refuse_count"),
                    @Result(property = "creater", column = "creater"),
                    @Result(property = "createTime", column = "create_time"),
                    @Result(property = "updater", column = "updater"),
                    @Result(property = "updateTime", column = "update_time"),
                    @Result(property = "fromerEmail", column = "fromer_email"),
                    @Result(property = "fromerUserName", column = "fromer_user_name"),
                    @Result(property = "fromerName", column = "fromer_name"),
                    @Result(property = "fromerUserType", column = "fromer_user_type"),
                    @Result(property = "fromerIdNumber", column = "fromer_id_number"),
                    @Result(property = "targeterUserName", column = "targeter_user_name"),
                    @Result(property = "targeterEmail", column = "targeter_email"),
                    @Result(property = "targeterName", column = "targeter_name"),
                    @Result(property = "targeterUserType", column = "targeter_user_type"),
                    @Result(property = "targeterIdNumber", column = "targeter_id_number"),
                    @Result(property = "fileName", column = "file_name"),
                    @Result(property = "savePath", column = "save_path"),
                    @Result(property = "reqRelUrl", column = "req_rel_url"),
                    @Result(property = "fileId", column = "file_id"),
                    @Result(property = "fromToMe", column = "from_to_me")
            }
    )
    List<CmsMeeting> selectByCondition(MeetingCondition mc);

    @SelectProvider(type = CmsMeetingProvider.class, method = "selectOvertimeByConditionProvider")
    @ResultMap(value = "cmsMeetingRow")
    List<CmsMeeting> selectOvertimeByCondition(MeetingCondition mc);

    @SelectProvider(type = CmsMeetingProvider.class, method = "selectNoticeErrProvider")
    @ResultMap(value = "cmsMeetingRow")
    List<CmsMeeting> selectNoticeErr();

    @SelectProvider(type = CmsMeetingProvider.class, method = "selectByPrimaryKeyProvider")
    @ResultMap(value = "cmsMeetingRow")
    CmsMeeting selectByPrimaryKey(String id);

    @SelectProvider(type = CmsMeetingProvider.class, method = "selectByCodeProvider")
    @ResultMap(value = "cmsMeetingRow")
    CmsMeeting selectByCode(String code);

    @Select("select * from `cms_meeting` where fromer = #{fromer} and application_content_id = #{resId}")
    CmsMeeting selectByFromerAndResId(@Param("fromer") String fromer, @Param("resId") String resId);

    @SelectProvider(type = CmsMeetingProvider.class, method = "countForUserProvider")
    int countForUser(MeetingCondition mc);

    @SelectProvider(type = CmsMeetingProvider.class, method = "selectForUserProvider")
    @ResultMap(value = "cmsMeetingRow")
    List<CmsMeeting> selectForUser(MeetingCondition mc);

    @Select("select b.* from `lib_expert` a, bus_user b where a.id_number = b.id_number and a.id = #{resId}")
    @Results({
        @Result(property = "id", column = "user_id"),
    })
    BusUser selectExpertByResId(@Param("resId") String resId);

    @Select("select b.* from `lib_requirements` a, bus_user b where a.code = b.id_number and a.id = #{resId}")
    BusUser selectReqByResId(@Param("resId") String resId);

    @Select("select b.* from `lib_results` a, bus_user b where a.code = b.id_number and a.id = #{resId}")
    BusUser selectResultByResId(@Param("resId") String resId);

    @Select("select b.* from `lib_service` a, bus_user b where a.org_code = b.id_number and a.id = #{resId}")
    BusUser selectServiceByResId(@Param("resId") String resId);

//    int deleteByExample(CmsMeetingExample example);
//
//    int deleteByPrimaryKey(String id);
//
//    int insert(CmsMeeting record);
//
//    List<CmsMeeting> selectByExampleWithBLOBs(CmsMeetingExample example);
//
//    List<CmsMeeting> selectByExample(CmsMeetingExample example);
//
//    int updateByExampleSelective(@Param("record") CmsMeeting record, @Param("example") CmsMeetingExample example);
//
//    int updateByExampleWithBLOBs(@Param("record") CmsMeeting record, @Param("example") CmsMeetingExample example);
//
//    int updateByExample(@Param("record") CmsMeeting record, @Param("example") CmsMeetingExample example);
//
//    int updateByPrimaryKeySelective(CmsMeeting record);
//
//    int updateByPrimaryKeyWithBLOBs(CmsMeeting record);
//
//    int updateByPrimaryKey(CmsMeeting record);
}